﻿#ifndef BROWSERMAINWINDOW_H
#define BROWSERMAINWINDOW_H

#include <QWidget>
#include <QWebEngineView>
#include <windows.h>        //注意头文件
#include <windowsx.h>
#include <QMouseEvent>
#include <QPainter>
#include <QWebEngineProfile>

#include "debugger.h"
#include "configmanager.h"
#include "tabbarwidget.h"
#include "settingmenu.h"
#include "passwordmanager.h"
#include "passwordmanagerwindow.h"
#include "favoritemanagerwindow.h"
#include "statusbarwidget.h"
#include "global.h"
#include "pluginmanagerwindow.h"
#include "themewindow.h"
#include "pagesearchwindow.h"
#include "configwindow.h"
#include "historymanagerwindow.h"

#pragma comment (lib,"user32.lib")

class Browser;
class TabBarWidget;

namespace Ui {
class BrowserMainWindow;
}

class BrowserMainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit BrowserMainWindow(Browser *browser, QWidget *parent = nullptr, QWebEngineProfile *profile = nullptr);
    ~BrowserMainWindow();

    TabBarWidget* tabWidget();

private:
    Ui::BrowserMainWindow *ui;
    // 自定义无边框窗口样式
    // 去掉系统边框自定义边框
    int boundaryWidth=4;
    // 鼠标点击的位置，用于计算移动窗口
    QPoint clickPoint;
    int counter;
    bool m_bResizeable = true;
    long m_borderWidth = 4;
    // 主题
    Theme currentTheme;
    // 设置菜单窗口
    SettingMenu* settingMenu;

    // 密码管理器实例
//    PasswordManager  *passwordManager;    // 直接做成单例模式
    // 密码管理器菜单界面
    PasswordManagerWindow *passwordMangerWindow;

    // 历史记录窗口
    HistoryManagerWindow *historyManagerWindow;

    // 收藏夹窗口
    FavoriteManagerWindow *favoriteManagerWindow;

    // 状态栏(就留一个就够了，多了费性能)
    StatusBarWidget *stausBarWidget;

    // 下载管理器
    DownloadWindow *downloadWindow;

    // 插件管理器
    PluginManagerWindow *pluginManagerWindow;

    // 主题设置窗口
    ThemeWindow *themeWindow;

    // 搜索
    PageSearchWindow *pageSearchWindow;

    // 设置窗口
    ConfigWindow *configWindow;

// 信号处理函数
public:
    void changeWebView(TabBarButton * ptr);
    void removeTab(TabBarButton *ptr);
    void changeInputUrl(QString url);
    void handleLinkHover(const QString &url);

    void handleShowDownloadWindow();
    void showPluginManagerWindow();

    // 切换主体
    void changeTheme(Theme theme);

    // 添加到收藏夹
    void addFavirote(UrlInfo info);
// 窗口重写
public:
    void repaint(int x, int y, int w, int h);

    void paintEvent(QPaintEvent *event) override;

    bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;

    // 键盘事件监听
    void keyReleaseEvent(QKeyEvent *event) override;

    void setDownloadWindow(DownloadWindow *downloadWindow){this->downloadWindow = downloadWindow;}

    void setPluginManagerWindow(PluginManagerWindow *pluginManagerWindow){this->pluginManagerWindow = pluginManagerWindow;}
signals:
    void showDownloadWindow();

private:
    QWebEngineProfile *profile;
};

#endif // BROWSERMAINWINDOW_H
